package com.lucenly.spell.utils

import android.os.Handler
import android.os.Looper
import android.view.Gravity
import android.widget.Toast
import com.lucenly.spell.app.MyApplication

/**
 *  Created by Yang on 2020/12/25 0025 18:57.
 *
 */
fun Any.ext_toast(text: String?, duration: Int = Toast.LENGTH_SHORT, gravity: Int = Gravity.BOTTOM) {
    ext_runOnMainThread {
        ToastZ.filterSameTextToast(text, duration, gravity)
    }
}

fun Any.ext_toast(text_res_id: Int, duration: Int = Toast.LENGTH_SHORT, gravity: Int = Gravity.BOTTOM) {
    ext_runOnMainThread {
        ToastZ.filterSameTextToast(MyApplication.instance.resources.getString(text_res_id), duration, gravity)             //TODO 有一定的可能，会出现内存泄露。
    }
}

fun Any.ext_runOnMainThread(
    your_Action: () -> Unit
) {
    Handler(Looper.getMainLooper()).post {
        your_Action.invoke()
    }
}